class SpineAnimation {
	private mAniPath:string;
	private mFactory:Laya.SpineTemplet;
	private mArmature:Laya.SpineSkeleton;
	private mIndex:number = 0;
	constructor() {
		Laya.init(Laya.Browser.width, Laya.Browser.height, Laya.WebGL);
		Laya.stage.bgColor = "#232628";
		Laya.Stat.show();
		this.StartFun();
	}

	private StartFun(): void {
		this.mAniPath =  "res/bone/spineboy.json";
		this.mFactory = new Laya.SpineTemplet();
		this.mFactory.on(Laya.Event.COMPLETE, this, this.parseComplete);
		this.mFactory.on(Laya.Event.ERROR, this, this.onError);
        this.mFactory.loadAni(this.mAniPath);
	}

	private parseComplete(): void {
		this.mArmature = this.mFactory.buildArmature();
		this.mArmature.x = 800;
		this.mArmature.y = 600;
		this.mArmature.scaleX = 0.8;
		this.mArmature.scaleY = 0.8;
		Laya.stage.addChild(this.mArmature);
		this.mArmature.on(Laya.Event.STOPPED, this, this.CompleteHandler);
        this.play();
	}

	private onError(): void {
		console.log("error")
	}

	private CompleteHandler(): void {
		this.play();
	}

	private play(): void {
		this.mIndex ++;
		if (this.mIndex >= this.mArmature.getAnimNum())
			{
				this.mIndex = 0;
			}
			this.mArmature.play(this.mIndex, false);
			
		}
}
new SpineAnimation();